package com.news.gpb.dao;

import com.news.gpb.entity.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

@Repository
public interface UserDao {

    @Select("select * from users where user_email=#{user.user_email} and user_password=#{user.user_password}")
    User getUser(@Param("user") User user);

    @Select("select * from users where user_id=#{user_id}")
    User getUserById(@Param("user_id") int user_id);

    @Select("select * from users where user_email=#{user_email}")
    User getUserByEmail(@Param("user_email") String user_email);

    @Select("select user_picture from users where user_id=#{user_id}")
    String getUserPicture(@Param("user_id")int user_id);

    @Insert("insert into users (user_email,user_password) values(#{user.user_email},#{user.user_password})")
    @Options(useGeneratedKeys = true,keyProperty = "user.user_id",keyColumn = "user_id")
    Integer insertUser(@Param("user") User user);

    @Update("update users set user_password=#{user.user_password} where user_email=#{user.user_email}")
    Integer editUser(@Param("user")User user);

    @Update("update users set user_picture=#{pathname} where user_id=#{user_id}")
    Integer uploadPic(@Param("pathname")String path,@Param("user_id")int user_id);
}
